import { Language } from "../../../extend/language/Language";
import { DailyRule } from "../rules/DailyRule";
import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { StringHelper } from "../../../com/gengine/utils/StringHelper";
import { LoginNoticeInfo } from "../model/LoginNoticeInfo";
import { ParamsConst } from "../../common/global/ParamsConst";
import { Cache } from "../cache/Cache";
import { ECareer } from "../../../Message/Public/ECareer";
import { Global } from "../../../com/gengine/global/Global";
import { ProxyType } from "../../common/global/ProxyType";
import { LoginNotice } from "../../../DailyRule/LoginNotice";
import { WelfareGet } from "../../../DailyRule/WelfareGet";
import { GiftGet } from "../../../DailyRule/GiftGet";
import { SpecialActive } from "../../../DailyRule/SpecialActive";
import { OpenServerAct } from "../../../DailyRule/OpenServerAct";
import { SpecialGift } from "../../../DailyRule/SpecialGift";
import { PhoneGift } from "../../../DailyRule/PhoneGift";
import { Mall360Gift } from "../../../DailyRule/Mall360Gift";
import { Gift91Wan } from "../../../DailyRule/Gift91Wan";
import { LoginSevenDays } from "../../../DailyRule/LoginSevenDays";
import { GetAnyGift } from "../../../DailyRule/GetAnyGift";
type int = number;
//class LoginNoticeConfig
    
    export  class LoginNoticeConfig
    {
        constructor()
        {
            this._addList = [];
            this._updateList = [];
            this._titleArray = [{"label": Language.getString(20130), "name":"1", "id": LoginNotice}, {"label": Language.getString(20131), "name":"2", "id": WelfareGet}, {"label": Language.getString(20507), "name":"3", "id": GiftGet}, {"label": Language.getString(21030), "name":"4", "id": SpecialActive}, {"label": Language.getString(70919), "name":"5", "id": OpenServerAct}, {"label": Language.getString(25005), "name":"6", "id": SpecialGift}, {"label": Language.getString(25006), "name":"7", "id": PhoneGift}, {"label": Language.getString(25012), "name":"8", "id": Mall360Gift}, {"label": Language.getString(25016), "name":"9", "id": Gift91Wan}, {"label": Language.getString(70901), "name":"10", "id": LoginSevenDays}, {"label": Language.getString(90313), "name":"11", "id": GetAnyGift}];
            
            if (LoginNoticeConfig._instance) 
            {
                throw new Error("LoginNoticeConfig is a single!");
            }
            return;
        }

        /* internal  */init(): void
        {
            var loc1=ConfigManager.instance.getObjectByFileName("LoginNotice.xml");
            this.write(loc1);
            return;
        }

        public writeXml(arg1: XML): void
        {
            this._addList.splice(0);
            this._updateList.splice(0);
            if (arg1.hasOwnProperty("rolltip")) 
            {
                this._roleTips = StringHelper.getString(arg1.rolltip.@msg);
            }
            if (arg1.hasOwnProperty("add")) 
            {
                this.parseXml(arg1.add.notices.notice, Language.getString(20620), this._addList, 0);
            }
            if (arg1.hasOwnProperty("update")) 
            {
                this.parseXml(arg1.update.notices.notice, Language.getString(20621), this._updateList, 1);
            }
            return;
        }

        /* internal  */parseXml(arg1: XMLList, arg2: string, arg3: Array<any>, arg4: int): void
        {
            var loc1=null;
            var loc2=null;
            var loc4=null;
            var loc5=null;
            var loc3=0;
            var loc6=0;
            var loc7=arg1;
            for(loc1 of loc7) 
            {
                (loc2 = new LoginNoticeInfo()).type = arg4;
                loc2.index = loc3;
                loc2.title = arg2;
                loc2.notice = loc1.@des;
                if (loc1.hasOwnProperty("item")) 
                {
                    loc4 = loc1.item;
                    var loc8=0;
                    var loc9=loc4;
                    for(loc5 of loc9) 
                    {
                        if (int(loc5.@id) == 0) 
                        {
                            continue;
                        }
                        loc2.itemIds.push(int(loc5.@id));
                    }
                }
                loc2.updateData();
                arg3.push(loc2);
                ++loc3;
            }
            return;
        }

        public write(arg1: Object): void
        {
            if (arg1.hasOwnProperty("rolltip")) 
            {
                this._roleTips = StringHelper.getString(arg1.rolltip.msg);
            }
            if (arg1.hasOwnProperty("add")) 
            {
                if (typeof arg1.add.notices.notice === "array") 
                {
                    this.parseArray(arg1.add.notices.notice, Language.getString(20620), this._addList, 0);
                }
                else 
                {
                    this.parseObj(arg1.add.notices.notice, Language.getString(20620), this._addList, 0);
                }
            }
            if (arg1.hasOwnProperty("update")) 
            {
                if (typeof arg1.update.notices.notice === "array") 
                {
                    this.parseArray(arg1.update.notices.notice, Language.getString(20621), this._updateList, 1);
                }
                else 
                {
                    this.parseObj(arg1.update.notices.notice, Language.getString(20621), this._updateList, 1);
                }
            }
            return;
        }

        /* internal  */parseArray(arg1: Array<any>, arg2: string, arg3: Array<any>, arg4: int): void
        {
            var loc1=0;
            var loc2=0;
            var loc3=null;
            var loc4=null;
            loc1 = 0;
            loc2 = arg1.length;
            while (loc1 < loc2) 
            {
                loc3 = arg1[loc1];
                (loc4 = new LoginNoticeInfo()).index = loc1;
                loc4.title = arg2;
                loc4.type = arg4;
                loc4.notice = loc3.des;
                if (loc3.hasOwnProperty("item")) 
                {
                    this.parseItem(loc3.item, loc4);
                }
                loc4.updateData();
                arg3.push(loc4);
                ++loc1;
            }
            return;
        }

        /* internal  */parseObj(arg1: Object, arg2: string, arg3: Array<any>, arg4: int): void
        {
            var loc2=null;
            var loc3=0;
            var loc4=0;
            var loc5=null;
            var loc1=arg1;
            (loc2 = new LoginNoticeInfo()).index = 0;
            loc2.title = arg2;
            loc2.type = arg4;
            loc2.notice = loc1.des;
            if (loc1.hasOwnProperty("item")) 
            {
                this.parseItem(loc1.item, loc2);
            }
            loc2.updateData();
            arg3.push(loc2);
            return;
        }

        /* internal  */parseItem(arg1: Object, arg2: LoginNoticeInfo): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=0;
            if (typeof arg1 === "array") 
            {
                loc2 = 0;
                loc3 = arg1.length;
                while (loc2 < loc3) 
                {
                    loc1 = arg1[loc2];
                    if (int(loc1.id) != 0) 
                    {
                        arg2.itemIds.push(int(loc1.id));
                    }
                    ++loc2;
                }
            }
            else 
            {
                loc1 = arg1;
                if (int(loc1.id) != 0) 
                {
                    arg2.itemIds.push(int(loc1.id));
                }
            }
            return;
        }

        public LoginNoticeConfig.get noticeMsg(): string
        {
            return this._roleTips;
        }

        public LoginNoticeConfig.get addList(): Array<any>
        {
            return this._addList;
        }

        public LoginNoticeConfig.get updateList(): Array<any>
        {
            return this._updateList;
        }

        public getInfoAsTabBarProvider(): Array<any>
        {
            var loc1=0;
            var loc3=null;
            var loc2=this._titleArray.length;
            var loc4=[];
            while (loc1 < loc2) 
            {
                loc3 = this._titleArray[loc1];
                if (loc3.id != DailyRule.SpecialActive) 
                {
                    if (loc3.id != DailyRule.SpecialGift) 
                    {
                        if (loc3.id != DailyRule.LoginNotice) 
                        {
                            if (loc3.id != DailyRule.PhoneGift) 
                            {
                                if (loc3.id != DailyRule.Mall360Gift) 
                                {
                                    if (loc3.id != DailyRule.Gift91Wan) 
                                    {
                                        if (loc3.id != DailyRule.OpenServerAct) 
                                        {
                                            if (loc3.id != DailyRule.LoginSevenDays) 
                                            {
                                                if (loc3.id == DailyRule.GetAnyGift) 
                                                {
                                                    if (!ParamsConst.instance.getAnyGiftUrl || ParamsConst.instance.getAnyGiftUrl == "") 
                                                    {
                                                        ++loc1;
                                                        continue;
                                                    }
                                                }
                                            }
                                            else if (Cache.instance.role.entityInfo.career == ECareer._ECareerNo || Cache.instance.role.entityInfo.career == ECareer._ECareerNewPlayer || !Cache.instance.loginNotice.isSeventDaysCanGetRewards) 
                                            {
                                                ++loc1;
                                                continue;
                                            }
                                        }
                                        else if (!(Cache.instance.daily.hasOpenServerAct && Cache.instance.daily.isShowOpenServer())) 
                                        {
                                            ++loc1;
                                            continue;
                                        }
                                    }
                                    else if (!ParamsConst.instance.Gift91Wan || ParamsConst.instance.Gift91Wan == "") 
                                    {
                                        ++loc1;
                                        continue;
                                    }
                                }
                                else 
                                {
                                    if (!Global.isDebugModle) 
                                    {
                                        if (ParamsConst.instance.proxyType != ProxyType.P360) 
                                        {
                                            ++loc1;
                                            continue;
                                        }
                                    }
                                    if (!ParamsConst.instance.Mall360GiftUrl || ParamsConst.instance.Mall360GiftUrl == "") 
                                    {
                                        ++loc1;
                                        continue;
                                    }
                                }
                            }
                            else if (!ParamsConst.instance.phoneUrl || ParamsConst.instance.phoneUrl == "") 
                            {
                                ++loc1;
                                continue;
                            }
                        }
                        else if (ParamsConst.instance.updateUrl == "-1") 
                        {
                            ++loc1;
                            continue;
                        }
                    }
                    else if (Cache.instance.loginNotice.specialAllTimeInfos.length == 0) 
                    {
                        ++loc1;
                        continue;
                    }
                }
                else if (!Cache.instance.daily.hasNormalActive) 
                {
                    ++loc1;
                    continue;
                }
                loc4.push(loc3);
                ++loc1;
            }
            return loc4;
        }

        public static get instance(): LoginNoticeConfig
        {
            if (!LoginNoticeConfig._instance) 
            {
                LoginNoticeConfig._instance = new LoginNoticeConfig();
            }
            return LoginNoticeConfig._instance;
        }

        /* internal */ /* var */_roleTips: string;

        /* internal */ /* var */_addList: Array<any>;

        /* internal */ /* var */_updateList: Array<any>;

        /* internal */ /* var */_titleArray: Array<any>;

        /* internal */ static /* var */_instance: LoginNoticeConfig;
    }
